<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>
	<link rel="stylesheet" href="http://127.0.0.1/jumeiphp/Public/Bootstrap/Css/bootstrap.min.css" />
	<link rel="stylesheet" href="http://127.0.0.1/jumeiphp/Application/Admin/View/Public/Css/common.css" />
	<script type="text/javascript" src="http://127.0.0.1/jumeiphp/Application/Admin/View/Public/Js/jquery-1.7.2.min.js"></script>
</head>
<body>
	<form action="" method="post">
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span12">
					<table class="table table-bordered table-hover">
						<thead>
							<tr pid="0">
								<th>
									分类ID
								</th>
								<th>
									分类名称
								</th>
								<th>
									排序
								</th>
								<th>
									操作
								</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach ($data as $k=>$v){?>
							<tr class="info" pid="<?php echo $v['pid'];?>" cid="<?php echo $v['cid'];?>">
								<td>
								<?php echo $v['cid'];?>
								</td>
								<td class='open' cid='<?php echo $v['cid'];?>'>
								<?php echo $v['_name'];?>
								</td>
								<td>
									<?php echo $v['csort'];?>
								</td>
								<td>
									<a href="<?php echo U('Admin/Category/add_son',array('cid'=>$v['cid']));?>" class="btn btn-success"><i class="icon-edit icon-white"></i>添加子分类</a>
									<a href="<?php echo U('Admin/Category/edit',array('cid'=>$v['cid']));?>" class="btn btn-warning"><i class="icon-pencil icon-white"></i>修改</a>
									<a href="<?php echo U('Admin/Category/del',array('cid'=>$v['cid']));?>" class="btn btn-danger"><i class="icon-trash icon-white"></i>删除</a>
								</td>
							</tr>
							<?php }?>
							<tr>
								<td colspan='4' align='center'>
									<input type="hidden" name='table' value='category' />
									<input type="submit" value='排序' class="btn btn-primary"/>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</form>

<script type="text/javascript">
$(function(){
	 // 所有的子集分类隐藏
        $('tr[pid!=0]').hide();
        // 点击展开收缩
        $('.open').toggle(function() {
            // 获得cid
            var cid = $(this).parents('tr').attr('cid');
            // 子分类显示
            $('tr[pid='+cid+']').fadeIn(500);
        }, function() {
            // 获得cid
            var cid = $(this).parents('tr').attr('cid');
            // 异步控制收缩，防止出现有的三级菜单点击收缩只能收起二级菜单，三级菜单不能一起收起
            $.ajax({
                url: "<?php echo U('Admin/Category/getSon');?>",
                type: 'post',
                dataType: 'json',
                data: {cid: cid},
                success:function(phpData){
                    // 遍历数组，让所有的子集分类隐藏
                    $.each(phpData, function(k, v) {
                        $('tr[cid='+v+']').fadeOut(500);
                    });
                }
            });
        });
});
</script>
</body>
</html>